<template>
  <!-- 商品卡片 -->
  <view class="goodsCardContainer">
    <!-- 商品图片 -->
    <view class="goodsImage">
      <image :src="goodsInfo.imgUrl" mode="aspectFit" lazy-load></image>
    </view>
    <!-- 商品名称 -->
    <view class="goodsName">
      <text>{{ goodsInfo.name }}</text>
    </view>
    <!-- 标签 -->
    <view class="tag">
      <text>{{ goodsInfo.tag }}</text>
    </view>
    <!-- 价格 -->
    <view class="price">
      <text class="amount">￥{{ goodsInfo.price }}</text>
      <text class="unit">/{{ goodsInfo.unit }}</text>
    </view>
    <!-- 加入购物车 -->
    <view class="addCar" @click="addShoppingCart(goodsInfo)">
      <text>+</text>
    </view>
  </view>
</template>

<script>
export default {
  name: "GoodsCard",
  props: {
    goodsInfo: {
      type: Object,
      required: true,
    },
  },
  methods: {
    addShoppingCart(goodsInfo) {
      this.$emit("addShoppingCart", goodsInfo);
    },
  },
};
</script>

<style lang="scss" scoped>
// 商品卡片
.goodsCardContainer {
  width: 332rpx;
  height: 471rpx;
  border-radius: 10rpx;
  background-color: #fff;
  position: relative;

  &:hover {
    box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
  }

  // 商品图片
  .goodsImage {
    width: 95%;
    height: 230rpx;
    line-height: 230rpx;
    margin: 15rpx auto;
    text-align: center;

    image {
      width: 90%;
      max-height: 100%;
    }
  }

  // 商品名称
  .goodsName {
    width: 280rpx;
    height: 45rpx;
    line-height: 45rpx;
    margin: 0 auto;
    font-size: 30rpx;
    color: #333;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
  }

  // 标签
  .tag {
    display: inline-block;
    padding: 10rpx 10rpx;
    font-size: 20rpx;
    color: #999;
    border: 1rpx solid #999;
    border-radius: 30rpx;
    margin: 15rpx 0;
    margin-left: 24rpx;
  }

  // 价格
  .price {
    width: 95%;
    height: 55rpx;
    line-height: 55rpx;
    margin: 30rpx auto;

    .amount {
      font-size: 36rpx;
      color: $main-color;
    }

    .unit {
      font-size: 26rpx;
      color: #999;
    }
  }

  // 加入购物车
  .addCar {
    width: 54rpx;
    height: 54rpx;
    line-height: 54rpx;
    text-align: center;
    border-radius: 50%;
    color: #fff;
    font-size: 36rpx;
    background-color: $main-color;
    position: absolute;
    bottom: 24rpx;
    padding: 0;
    right: 26rpx;
  }
}
</style>
